package promote.brozen.netty.echo;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

/**
 * @author Brozen
 * @date 2020/9/27 3:44 PM
 * @email brozen@qq.com
 */
public class NettyEchoChildChannelHandler extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 在这里添加对channel的处理器到pipeline
        ch.pipeline().addLast(new NettyEchoChannelReader());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
        System.out.println("客户端连接异常：" + ctx);
        cause.printStackTrace();
    }

}
